<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!doctype html>
<html class="no-js">
<head>
    <%@ include file="./../common/meta.jsp" %>
    <link rel="stylesheet" href="../../css/echu.css">

</head>
<body>
<header data-am-sticky class="am-header am-header-default am-no-layout">

    <div class="am-header-left am-header-nav">

        <a href="./login.jsp" class="">
            <i class="am-header-icon am-icon-chevron-left"></i>
        </a>
    </div>
    <h1 class="am-header-title">找回密码</h1>
</header>
<div class="am-content">

    <div class="am-container am-margin-top-lg">
        <div class="am-g">
            <div class="am-u-sm-12">
                <form method="post" class="am-form am-form-horizontal" id="login-form">
                    <div class="am-form-group">
                        <div class="am-u-sm-12">
                            <div class="am-form-icon">
                                <input type="text" name="account"
                                       id="account"
                                       class=""
                                       placeholder="输入您的手机号">
                                <button type="button" class="am-btn am-btn-default" id="sendMessage">点击发送</button>
                                <span id="djs"></span>
                            </div>
                        </div>
                    </div>


                    <div class="am-form-group">
                        <div class="am-u-sm-12">
                            <div class="am-form-icon">
                                <input type="text" name="securityCode"
                                       id="securityCode"
                                       class=""
                                       placeholder="请输入验证码">
                            </div>
                        </div>
                    </div>


                    <div class="am-form-group am-margin-bottom-sm">
                        <div class="am-u-sm-12">
                            <input type="button"
                                   id="regsubmit"
                                   value="提交"
                                   class="am-btn-block am-btn am-btn-primary am-btn-sm">
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>


<div class="am-modal am-modal-alert" tabindex="-1" id="modal-alert">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">提示</div>
        <div class="am-modal-bd"></div>
        <div class="am-modal-footer">
            <span class="am-modal-btn">确定</span>
        </div>
    </div>
</div>

<%@ include file="./../common/footer.jsp" %>


<script>
    $(function () {
        $("#sendMessage").click(function () {
            var phone = $("#account").val();
            if (phone == null || phone == "") {
                alert("请输入手机号");
                return false;
            }

            var reg = /^0?1[3|4|5|8|7][0-9]\d{8}$/;
            if (!reg.test(phone)) {
                alert("手机号格式不正确");
                return false;
            }

            var url = "/h5/sendMessage";
            $.post(url, {
                phone: phone
            }, function (result) {
                if (result == '000001') {
                    alert("账号不存在");
                }else {
                    alert("发送成功");
                    $("#sendMessage").attr("disabled", "disabled");
                    var t = setInterval(djs, 1000);

                    function djs() {
                        var spanText = $("#djs").text();
                        if (spanText == "") {
                            spanText = "60";
                        }
                        $("#djs").text(parseInt(spanText) - 1)
                        if (spanText == "1") {
                            $("#sendMessage").attr("disabled", false);
                            clearTimeout(t);
                            $("#djs").text("");

                        }
                    }


                }
            });
        })


        $("#regsubmit").click(function () {
            var phone = $("#account").val();
            var securityCode = $("#securityCode").val();
            if (phone == null || phone == "") {
                alert("请输入手机号");
                return false;
            }

            var reg = /^0?1[3|4|5|8|7][0-9]\d{8}$/;
            if (!reg.test(phone)) {
                alert("手机号格式不正确");
                return false;
            }

            var url = "/h5/checkCode";
            $.post(url, {
                phone: phone,
                code: securityCode
            }, function (result) {
                if (result == '000001') {
                    alert("账号不存在");
                } else if (result == "000002") {
                    alert("验证码已经过期,请重新发送");
                } else if (result == "000003") {
                    alert("验证码不存在");
                } else {
                    window.location.href = "./password.jsp?account=" + phone;
                }
            });
        })


    })


</script>


</body>
</html>